// import Vue from 'vue'
import router from './router'
import store from './store'
import * as types from '@/store/mutation-types'
import app from '@/main'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// 白名单页面 不判断登陆
const whiteList = ['login', 'regist', 'wxRank']
router.beforeEach((to, from, next) => {
    NProgress.start();
    const title = to.meta && to.meta.title;
    if (title) {
        document.title = title;
    }

    // if (!to.name || whiteList.indexOf(to.name.toLowerCase().replace('/', '')) == -1) {
    //     // console.log('+++++');
    //     //非白名单链接  需要判断是否登录
    //     var loginInfo = store.state.user.loginInfo

    //     var token = app.config.globalProperties.ls.get(types.ACCESS_TOKEN)
    //     if (!loginInfo.id) {
    //         if (token) {
    //             store.dispatch('user/GetInfo').then(() => {
    //                 loginInfo = store.state.user.loginInfo
    //                 app.config.globalProperties.$message.info(`欢迎回来，${loginInfo.groupName} - ${loginInfo.name}`);
    //                 const hide = app.config.globalProperties.$message.loading(`正在玩命初始化基金信息...`, 0);

    //                 store.dispatch('user/GetMyFund').then(() => {
    //                     hide()
    //                     next('/');
    //                 }).catch(() => {
    //                     next('/');
    //                 })


    //             }).catch(() => {
    //                 next('/login');
    //             })
    //         } else {
    //             next('/login');
    //         }

    //     }
    // }

    next()
})

router.afterEach(() => {
    NProgress.done() // finish progress bar
})